home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / pipeln10.zip / PIPELINE.ASM < prev    next >
Assembly Source File  |  1990-06-01  |  7KB  |  251 lines

  1. ;**************************************************************************
  2. ;*     PIPELINE vers 1.0, DOS                                             *
  3. ;*     Connects COM1 and COM2 in software.                                *
  4. ;*     6/1/90                                                             *
  5. ;*     by James W. Birdsall                                               *
  6. ;*                                                                        *
  7. ;*     assembles under Turbo Assembler 1.0, 2.0                           *
  8. ;*                                                                        *
  9. ;*     requires DOS 2.0 or higher                                         *
  10. ;*                                                                        *
  11. ;*   This program is a small TSR that connects COM1 and COM2 in software. *
  12. ;*   It is run from the command line with no arguments. After             *
  13. ;*   installation, setup and activation is performed with the program     *
  14. ;*   VALVE.                                                               *
  15. ;*                                                                        *
  16. ;*   This program can share an interrupt vector. It can be set to chain   *
  17. ;*   to the previous interrupt handler if examination of the serial port  *
  18. ;*   shows that no interrupt is pending.                                  *
  19. ;*                                                                        *
  20. ;**************************************************************************
  21.  
  22. LOCALS
  23. .MODEL tiny
  24.  
  25.  
  26. ENVOFFSET    EQU    2Ch
  27.  
  28. INTERFACEINT    EQU    0F1h
  29.  
  30.  
  31. ; TO CHANGE FROM COM1 OR COM2, CHANGE THE FOLLOWING INTERRUPT AND PORT
  32. ; VALUES.
  33. COM1INT        EQU    0Ch
  34. COM2INT        EQU    0Bh
  35.  
  36. COM1BASE    EQU    3F8h
  37. COM1IER        EQU    3F9h
  38. COM1IIR        EQU    3FAh
  39. COM1LSR        EQU    3FDh
  40.  
  41. COM2BASE    EQU    2F8h
  42. COM2IER        EQU    2F9h
  43. COM2IIR        EQU    2FAh
  44. COM2LSR        EQU    2FDh
  45. ; END OF INTERRUPT AND PORT VALUES
  46.  
  47.  
  48. EOI        EQU    20h
  49. EOIPORT        EQU    20h
  50.  
  51. OVERRUNMASK    EQU    02h
  52. INTPENDMASK    EQU    01h
  53. THREMASK    EQU    20h
  54.  
  55.  
  56. .CODE
  57.     ORG    100h
  58. start:
  59.     jmp    Install            ; jump to installation code
  60.  
  61. ; DATA AREA
  62.  
  63. errors        dw    0
  64. int_B        dd    0
  65. old_int_B    dd    0
  66. int_C        dd    0
  67. old_int_C    dd    0
  68. PSPseg        dw    0
  69. old_interface    dd    0
  70. enabled         db      0
  71. chain        db    0
  72.  
  73.  
  74. ; HANDLER FOR COM1 INTERRUPTS
  75.  
  76. Com1handler:
  77.     sti                ; enable interrupts
  78.         push    ax            ; preserve
  79.         push    bx
  80.         push    dx
  81.     mov    dx, COM1LSR        ; check for overruns
  82.         in    al, dx            ; read LSR
  83.         test    al, OVERRUNMASK
  84.         jz    @@NoOverrun        ; if zero, OK
  85.         inc    cs:errors
  86. @@NoOverrun:
  87.         mov    dx, COM1IIR
  88.         in    al, dx            ; read interrupt identification
  89.         test    al, INTPENDMASK
  90.         jnz    @@NotOurs
  91.         mov    dx, COM1BASE        ; read character
  92.         in    al, dx
  93.         mov    bl, al            ; put in BL for safekeeping
  94.         mov    dx, COM2LSR        ; check COM2 transmit status
  95.         in    al, dx
  96.         test    al, THREMASK        ; check for transmit buffer empty
  97.         jz    @@NoSend        ; if nonzero, can't transmit
  98.         mov    dx, COM2BASE        ; otherwise send char
  99.         mov    al, bl            ; put char back in AL
  100.         out    dx, al
  101. @@NotOurs:
  102.     test    cs:chain, 0FFh        ; is chain zero?
  103.         jz    @@SendEOI        ; if so, return normally
  104.         pushf                ; otherwise call old ISR
  105.         call    cs:old_int_C
  106.         jmp    @@Final            ; since old ISR sent EOI, don't resend
  107. @@NoSend:
  108.     inc    cs:errors        ; increment errors
  109. @@SendEOI:
  110.     mov    al, EOI            ; send EOI
  111.         out    EOIPORT, al
  112. @@Final:
  113.         pop    dx            ; restore
  114.         pop    bx
  115.         pop    ax
  116.         iret                ; return
  117.  
  118.  
  119. ; HANDLER FOR COM2 INTERRUPTS
  120.  
  121. Com2handler:
  122.     sti                ; enable interrupts
  123.         push    ax            ; preserve
  124.         push    bx
  125.         push    dx
  126.     mov    dx, COM2LSR        ; check for overruns
  127.         in    al, dx            ; read LSR
  128.         test    al, OVERRUNMASK
  129.         jz    @@NoOverrun        ; if zero, OK
  130.         inc    cs:errors
  131. @@NoOverrun:
  132.         mov    dx, COM2IIR
  133.         in    al, dx            ; read interrupt identification
  134.         test    al, INTPENDMASK
  135.         jnz    @@NotOurs
  136.         mov    dx, COM2BASE        ; read character
  137.         in    al, dx
  138.         mov    bl, al            ; put in BL for safekeeping
  139.         mov    dx, COM1LSR        ; check COM2 transmit status
  140.         in    al, dx
  141.         test    al, THREMASK        ; check for transmit buffer empty
  142.         jz    @@NoSend        ; if nonzero, can't transmit
  143.         mov    dx, COM1BASE        ; otherwise send char
  144.         mov    al, bl            ; put char back in AL
  145.         out    dx, al
  146. @@NotOurs:
  147.     test    cs:chain, 0FFh        ; is chain zero?
  148.         jz    @@SendEOI        ; if so, return normally
  149.         pushf                ; otherwise call old ISR
  150.         call    cs:old_int_B
  151.         jmp    @@Final            ; since old ISR sent EOI, don't resend
  152. @@NoSend:
  153.     inc    cs:errors        ; increment errors
  154. @@SendEOI:
  155.     mov    al, EOI            ; send EOI
  156.         out    EOIPORT, al
  157. @@Final:
  158.         pop    dx            ; restore
  159.         pop    bx
  160.         pop    ax
  161.         iret                ; return
  162.  
  163.  
  164. ; SIGNATURE USED FOR INSTALLATION CHECK
  165.  
  166. signature    db    'JWBP10'
  167.  
  168.  
  169. ; INTERFACE INTERRUPT HANDLER -- RETURNS POINTER TO DATA AREA
  170.  
  171. Interface:
  172.     mov    ax, cs            ; put segment in AX
  173.         mov    bx, offset errors    ; put offset in BX
  174.         iret                ; and return
  175.  
  176.  
  177. ; INSTALLATION CODE -- IS DISCARDED AFTER INSTALLATION
  178.  
  179. Last_byte:
  180.  
  181. OKmessage    db    'PIPELINE installed OK.',0Dh,0Ah,'$'
  182. FAILmessage    db    'PIPELINE installation error.',0Dh,0Ah,'$'
  183. COPYRIGHT    db    'Copyright (c) 1990 James W. Birdsall.'
  184. COPYRIGHT2    db    'All Rights Reserved.'
  185.  
  186. Install:
  187.         mov    bx, es            ; copy PSP segment from ES into BX
  188.         mov    PSPseg, bx        ; put into storage
  189.         mov    si, ENVOFFSET
  190.         mov    ax, es:si        ; move environment segment into AX
  191.         or    ax, ax            ; check it
  192.         jz    Continue        ; if zero, no environment
  193.         mov    es, ax            ; put env seg in ES
  194.         mov    ah, 49h            ; free block
  195.         int    21h
  196.         jc    Fail            ; if carry set, error
  197. Continue:
  198.                     ; put far ptrs to handlers in storage
  199.     mov    WORD PTR [int_B], offset Com2handler
  200.         mov    WORD PTR [int_C], offset Com1handler
  201.         mov    ax, cs
  202.         mov    WORD PTR [int_B+2], ax
  203.         mov    WORD PTR [int_C+2], ax
  204.  
  205.         mov    ah, 35h                ; get old int 0Bh vector
  206.         mov    al, 0Bh
  207.         int    21h
  208.         mov    WORD PTR [old_int_B], bx    ; and put in old_int_B
  209.         mov    bx, es
  210.         mov    WORD PTR [old_int_B+2], bx
  211.  
  212.         mov    ah, 35h                ; get old int 0Ch vector
  213.         mov    al, 0Ch
  214.         int    21h
  215.         mov    WORD PTR [old_int_C], bx    ; and put in old_int_C
  216.         mov    bx, es
  217.         mov    WORD PTR [old_int_C+2], bx
  218.  
  219.         mov    ah, 35h                ; get old interface vector
  220.         mov    al, INTERFACEINT
  221.         int    21h
  222.         mov    WORD PTR [old_interface], bx    ; and put in old_interface
  223.         mov    bx, es
  224.         mov    WORD PTR [old_interface+2], bx
  225.         mov    ah, 25h                ; set up interface
  226.         mov    al, INTERFACEINT
  227.         mov    dx, offset Interface
  228.         int    21h
  229.  
  230.         mov    ah, 09h                ; print OK message
  231.         mov    dx, offset OKmessage
  232.         int    21h
  233.  
  234.         mov    dx, offset Last_byte        ; go resident with code 0
  235.         add    dx, 15
  236.         mov    cl, 4
  237.         shr    dx, cl
  238.         mov    ah, 31h
  239.         xor    al, al
  240.         int    21h
  241. Fail:
  242.     mov    ah, 09h                ; print FAIL message
  243.         mov    dx, offset FAILmessage
  244.         int    21h
  245.  
  246.     mov    ah, 4Ch                ; exit with code 3
  247.         mov    al, 3
  248.         int    21h
  249.         END     start
  250. END
  251.